#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
void file_it(ostream &os,double fo,const double fe[],int n);
const int LIMIT = 5;
int main()
{
    // 定义输出文件类
    ofstream fout;
    const char * fn = "ep-data";
    fout.open(fn);
    if(!fout.is_open())
    {
	    cout<<"不能打开文件，准备退出!"<<endl;
	    exit(EXIT_FAILURE);
    }
    double objective;
    cout<<"输入长度:";
    cin >> objective;
    double eps[LIMIT];
    cout<<"输入长度:";
    for(int i = 0;i<LIMIT;i++){
        cout<<"Eyepiecs #"<<i+1<<":";
        cin>>eps[i];
    }
    file_it(fout,objective,eps,LIMIT);
    file_it(cout,objective,eps,LIMIT);
    cout<<"Done \n";
    return 0;
}
void file_it(ostream &os,double fo,const double fe[],int n)
{
	ios_base::fmtflags initial;
	initial = os.setf(ios_base::fixed);//定点显示
	os.precision(0);
	os<<"Focal length:"<<fo<<"mm\n";
	os.setf(ios::showpoint);//显示小数点，即使是整数
	os.precision(1);//显示小数点后一位
	os.width(12);//下一次输出操作制定的字段宽度，这种设置只在显示下一个值时有效，然后恢复默认字段宽度0
	os<<"f.1. eye";//
	os.width(15);
	os<<"magnification"<<endl;
	for(int i = 0;i<n;i++){
	    os.width(12);
	    os<<fe[i];
	    os.width(15);
	    os<<int(fo/fe[i]+0.5)<<endl;
	}
	os.setf(initial);
}

